<fieldset style="width:800px;border:solid 1px #A4BED4;margin-bottom:10px;margin-left:-1px;position:relative;">
    <legend>检索条件</legend>
    <div>
        <table style="width:100%;table-layout:fixed;">
            <tbody>
            <tr id="edit_boxs">
                <td style="width:100px;">机构：</td>
                <td style="width:150px;"><input id="agency" class="easyui-combotree" value="" data-options="url:'/oa/agencyListAll'" style="width:130px;"></td>

                <td style="width:40px;">员工：</td>
                <td style="width:150px;"><input id="staff" class="text"></td>
            </tr>
            <tr>
                <td>开始时间：</td>
                <td><input id="start_time" class="date" style="width:130px"></td>
                <td>截至时间</td>
                <td><input id="end_time" class="date" style="width:130px"></td>
                <td colspan="2" style="width: 100px;"><a href="javascript:void(0)" id="select" class="button"><span class="button-text">检索...</span></a></td>
            </tr>
            </tbody>
        </table>
    </div>
</fieldset>
<table id="attendance"></table>


<script type="text/javascript">
$(document).ready(function(){

    // 初期化DataGrid
    $('#attendance').datagrid({
        width:1080,
        height:400,
        nowrap: true,
        autoRowHeight: false,
        striped: true,
        url:'/oa/attendancePattern',
        sortName: 'id',
        remoteSort: false,
        queryParams:{},
        idField:'id',
        pagination:true,
        rownumbers:true,
        pageList:[10,15,20],
        frozenColumns:[[
            {field:'ck',checkbox:true},
        ]],
        columns:[[
            {field:'name',title:'姓名',width:120},
//            {field:'login_name',title:'登录帐号',width:120},

            {field:'attendance_date',title:'考勤日期',width:150,rowspan:2},
            {field:'attendance_time_start',title:'考勤开始时间',width:150,rowspan:2},
            {field:'attendance_time_end',title:'考勤结束时间',width:150,rowspan:2},
            {field:'agency_name',title:'所在机构',width:220,rowspan:2,sortable:true,
                sorter:function(a,b){
                    return (a>b?1:-1);
                }
            }
        ]],
        toolbar:
                [{
                    id: 'remove-l',
                    text:'删除选中考勤记录',
                    iconCls:'icon-remove',
                    handler:function(){
                        var ids  = "";

                        parent.$.dooDialog.confirm("你确定要删除这个考勤吗？",function(){
                            var rows = $('#attendance').datagrid('getSelections');
                            if( rows.length > 0 ){
                                for(var i=0;i<rows.length;i++){
                                    if(i==0){
                                        ids = rows[i].id;
                                    }else{
                                        ids = ids + "," + rows[i].id;
                                    }
                                }

                                $.post('/oa/attendanceDel',{deleted:ids},function(data){
                                    if(data.code=='OK'){
                                        $("#attendance").datagrid('reload');
                                    }else{
                                        parent.$.dooDialog.alert('考勤记录删除失败！');
                                    }
                                },'json');
                            }else{
                                parent.$.dooDialog.alert('您还没有选择要删除的记录，请选择......');
                            }
                        });
                    }
                }],
        onUnselect:function(rowIndex, field, value){
            $('#ClickRowID').val();
            $('#ClickRowName').val('');
            $('#ClickRowTypes').val('');
            $('#ClickRowBrand').val('');
            $('#ClickRowPattern').val('');
            $('#ClickRowRemark').val('');
        },
        onLoadSuccess:function(){
            if (JS.user.id == 1) {

            } else {
                $('#remove-l').hide();
                $('#edit_boxs').hide();
            }
        }
    });

    // 下拉框设置
    $('#department').combogrid({
        panelWidth:350,
        panelHeight:250,
        rownumbers:true,
        idField:'id',
        textField:'name',
        url:'/oa/departmentPattern',
        pagination:true,
        pageList:[10],
        columns:[[
            {field:'id',title:'ID',width:150},
            {field:'name',title:'部门',width:154}
        ]]
    });

    // 下拉框设置
    $('#staff').combogrid({
        panelWidth:350,
        panelHeight:250,
        rownumbers:true,
        idField:'id',
        textField:'name',
        url:'/oa/staffPattern/',
        pagination:true,
        pageList:[10],
        columns:[[
            {field:'id',title:'ID',width:150},
            {field:'name',title:'姓名',width:154}
        ]]
    });

    $('#ClickRowForecastTime').timespinner({
        showSeconds:true
    });

    // 检索功能
    $('a#select').click(function(){
        var queryParams = $('#attendance').datagrid('options').queryParams;
        queryParams.agency = $('#agency').next("span").find("input[type='hidden']").val();
        queryParams.department = $('#department').next("span").find("input[type='hidden']").val();
        queryParams.staff = $('#staff').next("span").find("input[type='hidden']").val();
        queryParams.start_time = $('#start_time').next("span").find("input[type='hidden']").val();
        queryParams.end_time = $('#end_time').next("span").find("input[type='hidden']").val();

        $('#attendance').datagrid('options').queryParams=queryParams;
        $("#attendance").datagrid('reload');
    });
});
</script>